/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tos.bakery;

/**
 *
 * @author Milos
 */

/* Klasa koja sadrzi promenljive za kontrolu*/
public class Variables 
{
    // Promenljiva koja prikazuje koji proces je na redu
    private int noOfProcesses;
    // Niz koji cuva promenljive koje opisuju da li su
    // procesi zainteresovani za kriticnu sekciju
    private boolean [] choose;
    private int [] numbers;

    // Konstruktor
    public Variables(int noOfProcesses)
    {
        this.noOfProcesses = noOfProcesses;
        choose = new boolean [noOfProcesses];
        numbers = new int [noOfProcesses];

        for (int i = 0; i < noOfProcesses; i++)
        {
            choose [i] = false;
            numbers [i] = 0;
        }
    }

    public boolean[] getChoose() {
        return choose;
    }

    public void setChoose(boolean[] choose) {
        this.choose = choose;
    }

    public int getNoOfProcesses() {
        return noOfProcesses;
    }

    public void setNoOfProcesses(int noOfProcesses) {
        this.noOfProcesses = noOfProcesses;
    }

    public int[] getNumbers() {
        return numbers;
    }

    public void setNumbers(int[] numbers) {
        this.numbers = numbers;
    }

    public void setChoose (int index, boolean want)
    {
        choose [index] = want;
    }

    public boolean getChoose (int index)
    {
        return choose [index];
    }

    public int getMaxNumber ()
    {
        int max = 0;

        for (int i = 0; i < noOfProcesses; i++)
        {
            if (numbers [i] > max)
            {
                max = numbers [i];
            }
        }

        max++;

        return max;
    }

    public void setNumber (int index, int value)
    {
        numbers [index] = value;
    }

    public int getNumber (int index)
    {
        return numbers [index];
    }
}
